#!/bin/sh
PACKNAME="x86_pkg.tar.gz"
pack()
{
  FWM_FDD_IMG="lte_fddzm.img"
  FWM_TDD_IMG="lte_tddzm.img"
  touch upgrade_all
  if [ -f $FWM_FDD_IMG ]; then
      md5sum $FWM_FDD_IMG > $FWM_FDD_IMG.md5sum 
  fi    

  if [ -f $FWM_TDD_IMG ]; then
      md5sum $FWM_TDD_IMG > $FWM_TDD_IMG.md5sum
  fi

  ipkList=`ls -l |grep 'ipk$' | awk '{print $9}'`
  for i in $ipkList
  do
    md5sum $i > $i.md5sum
  done

  ls -l *.ipk > /dev/null
  if [ $? -eq 0 ]; then
    ls -l *img > /dev/null
    if [ $? -eq 0 ]; then
      tar -zcf $PACKNAME.tar.gz *.img *.md5sum   *.ipk upgrade_all
    else
      tar -zcf $PACKNAME.tar.gz *.ipk *.md5sum  upgrade_all    
    fi
  else
    tar -zcf $PACKNAME.tar.gz *.img *.md5sum  upgrade_all 
  fi 
  rm *.img  *.md5sum *.ipk
  echo packet file ok
   
}

while getopts p: opt
do 
  case "$opt" in
      p) PACKNAME="$OPTARG";pack;;
      \?) echo "not support"
  esac
done
